package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {
    void insertOrder(Orders orders);


    void insertOrderDetails(List<OrderDetail> orderDetailList);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(@Param("orderNumber") String orderNumber, @Param("userId") Long userId);

    void update(Orders orders);

    /**
     * 分页条件查询并按下单时间排序
     * @param ordersPageQueryDTO
     */
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    @Select("select count(id) from orders where status = #{status} ")
    Integer countStatus(Integer toBeConfirmed);

    @Select("select * from orders where status = #{status} and order_time < #{time}")
    List<Orders> selectByStatusAndTime(@Param("status") Integer status, @Param("time") LocalDateTime time);

    /**
     * 统计营业额
     * @param queryParam 开始时间，结束时间，订单状态）
     * @return
     */
    Double selectByMap(Map queryParam);

    /**
     * 统计订单
     * @param queryParam（开始时间，结束时间，订单状态）
     * @return
     */
    Long selectByCount(Map queryParam);

    List<GoodsSalesDTO> selectSalesTop10(@Param("begin") LocalDate begin, @Param("end") LocalDate end);
}
